package com.itheima.d3_udp2.ZengUdpTest;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * @ClassName Server
 * @Author 16799
 * @Date 2025/9/25 23:38
 * @Version 1.0
 * @Description TODO
 **/
public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("-------服务端启动----------");
        DatagramSocket socket = new DatagramSocket(6622);

        byte[] buffer = new byte[1024*64];
        DatagramPacket packet = new DatagramPacket(buffer,buffer.length);
        while (true){
            socket.receive(packet);

            int len = packet.getLength();
            String msg = new String(buffer,0,len);
            System.out.println(msg);

            System.out.println("客户端的IP地址信息： " + packet.getAddress().getHostAddress());
            System.out.println("客户端的端口号： " + packet.getPort());

            System.out.println("----------------------");
        }
    }
}
